package com.heima.mapper;

import com.github.pagehelper.Page;
import com.heima.dto.ContractPageQueryDto;
import com.heima.pojo.Contract;
import com.heima.vo.ContractVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ContractMapper {
    /**
     * 分页查询合同
     * @param contractPageQueryDTO
     * @return
     */
    Page<ContractVo> pageQueryContract(ContractPageQueryDto contractPageQueryDTO);

    /**
     * 根据id查询合同
     * @param id
     * @return
     */
    @Select("select * from tb_contract where id = #{id}")
    ContractVo getById(Long id);

    /**
     * 修改合同
     * @param contractVo
     */
    void updateContract(ContractVo contractVo);

    /**
     * 新增合同
     * @param contract
     */
    @Insert("insert into tb_contract(contract_no,name,phone,subject,course_id,activity_Id,channel,create_time,channel_name,active_name) " +
            "values(#{contractNo},#{name},#{phone},#{subject},#{courseId},#{activityId},#{channel},#{createTime},#{channelName},#{activeName})")
    void addContract(Contract contract);

    /**
     *  根据渠道编号查询渠道名称
     * @param channel
     * @return
     */
    @Select("select dict_label from tb_dictionary where dict_value = #{channel} and dict_type = 'clues_item'")
    String getChannelName(String channel);

    /**
     * 根据活动编号查询活动名称
     * @param activityId
     * @return
     */
    @Select("select name from tb_active where id = #{activityId}")
    String getActiveName(Integer activityId);
}
